<?php

class Common_QCloud
{
    public function __construct()
    {
        require_once 'src/QcloudApi/QcloudApi.php';
        require_once 'src/QcloudApi/Common/Request.php';
    }


    public function load($model,$interface,$package=[])
    {
        $config = [
            'SecretId' => 'AKIDy9KOJVxpy7DA3ooXformlhm5KRQEekRj',
            'SecretKey' => 'KXcYMzRhsvqeHl6RvKcjiYuAHD0c4BEA',
            'RequestMethod' => 'GET',
            'DefaultRegion' => 'sh'
        ];

        $service = QcloudApi::load($model, $config);

        $url = $service->generateUrl($interface, $package);


        if ($url === false) {
            // 请求失败，解析错误信息
            $error = $service->getError();
            return "Error code:" . $error->getCode() . ' message:' . $error->getMessage();
            // 对于异步任务接口，可以通过下面的方法获取对应任务执行的信息
//            $detail = $error->getExt();
        } else {
            // 请求成功,生成url地址
            return $url;
        }





    // 生成请求的URL，不发起请求
//        $requestHost = 'live.api.qcloud.com';
//        $requestPath = 'v2/index.php';
//        $paramArray, $secretId, $secretKey, $requestMethod, $requestHost, $requestPath
//        $url = QcloudApi_Common_Request::generateUrl($config,$config['SecretId'],$config['SecretKey'],$config['RequestMethod'],$requestHost,$requestPath);


    }
}


